<?php
Class Articles_model extends CI_Model {
  
  function getarticlestypes() {
    $sql = "select * from ArticuloTipo";
    $query = $this->db->query($sql);
    return $query->result();
  }

  function getallarticles() {
    $sql = "select * from Articulos";
    $query = $this->db->query($sql);
    return $query->result();
  }

  function getallarticlesstatus() {
    $sql = "select id_estado, ds_estado from ArticuloEstado";
    $query = $this->db->query($sql);
    return $query->result();
  }

  function getarticletypebyid($id) {
    $sql = "SELECT * FROM ArticuloTipo where id_articulotipo = '$id'";
    $query = $this->db->query($sql);
    return $query->result();
  }

  function getarticlebyid($id) {
    $sql = "SELECT * FROM Articulos where id_articulo = '$id'";
    $query = $this->db->query($sql);
    return $query->result();
  }

  //Saves a article type into the database
  function savetype($articletypeid, $articletypename) {
	  $sql = "Save_ArticleType '$articletypeid', '$articletypename'"; 
    $query = $this->db->query($sql);
    return $query->num_rows();
  }

  function savearticle($articleid, $articlename, $articletype, $articledescription, $articlefeatures, $articlecomments) {
  	$sql = "Save_Article '$articleid', '$articlename', '$articletype', '$articledescription', '$articlefeatures', '$articlecomments'"; 
    $query = $this->db->query($sql);
    return $query->num_rows();
  }

}
?>